<template>
	<view class="content">
		<view class="address-box">
			<view class="address-item flexWrapNo" v-for="(item,index) in addressList" :key="index" @tap="selectAddress(index)">
				<view class="select-icon">
					<image src="../../static/coupon/select-icon.png" class="delete-icon"></image>
					<!-- <image src="../../static/order/notselect-icon.png" class="delete-icon"></image> -->
				</view>
				<view class="address-info">
					<view class="address-details flexWrapNo">
						<text class="lable">{{item.tag}}</text>
						<view class="address-name">{{item.address}}</view>
					</view>
					<!-- <view class="address-name">{{item.address}}</view> -->
					<view class="user-info">{{item.receiver}} {{item.mobile}}</view>
				</view>
				<image src="../../static/shop/edit-icon.png" class="edit-icon" @tap.stop="goPage('/pages/shop/editAddress?addressId='+item.id)"></image>
			</view>
			<view class="empty-box" v-if="addressList.length==0">
				<image src="https://static.mo-yu.vip/wechat/images/orderEmpty.png"></image>
			</view>
		</view>
		<view class="bottom-box flexWrap">
			<view class="btn flexWrapNo">
				<image src="../../static/shop/wechat-icon.png" class="wechat-icon"></image>
				微信导入
			</view>
			<view class="define-btn" @tap="goPage('/pages/shop/editAddress')">新增收货地址</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList:[]
			};
		},
		onShow() {
			this.getData();
		},
		methods:{
			getData(){
				this.$request.get(this.$api.addressList, {
					store_id:uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					if (res.code==1) {
						let {data}=res
						this.addressList=data
					}
				})
			},
			addressDel(index){
				uni.showModal({
					title:"提示",
					content:"是否删除？",
					success: (res) => {
						if(res.confirm){
							this.$request.get(this.$api.addressDel, {
								store_id:uni.getStorageSync('store_id'),
								id:this.addressList[index].id
							}, {
								token:true
							}).then(res => {
								if (res.code==1) {
									this.addressList.splice(index,1)
								}
							})
						}
					}
				})
			},
			selectAddress(index){
				let pages = getCurrentPages(); //当前页
				let beforePage = pages[pages.length - 2]; //上个页面
				beforePage.$vm.addressInfo =this.addressList[index]
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 44upx 36upx;
	}
	.bottom-box{
		height: 120rpx;
		background: #1D1C5C;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		padding: 0 66upx;
		.btn{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color:#28C445;
			width: 282rpx;
			height: 80rpx;
			line-height: 80rpx;
			border-radius: 16rpx;
			border: 2rpx solid #28C445;
			text-align: center;
			justify-content: center;
			.wechat-icon{
				width: 48upx;
				height: 48upx;
				margin-right: 8upx;
			}
		}
		.define-btn{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 80rpx;
			width: 282rpx;
			height: 80rpx;
			background: #26BCFD;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			text-align: center;
		}
	}
	.address-box{
		.address-item{
			border-bottom: 1rpx solid #36355E;
			padding-bottom: 32upx;
			margin-bottom: 32upx;
			.select-icon{
				width: 42upx;
				height: 42upx;
				flex: none;
			}
			.address-info{
				margin-left: 26upx;
				flex: 1;
				.address-name{
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					margin: 12upx 0;
				}
				.address-details{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color:#8584A0;
					.lable{
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						display: inline-block;
						border-radius: 8rpx;
						padding:4upx 8upx;
						background: #2CA522;
						flex: none;
						margin-right: 8upx;
					}
					.default{
						background:#26BCFD;
					}
					.company{
						background:#FF4646;
					}
				}
				.user-info{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color:#8584A0;
				}
			}
			.edit-icon{
				width: 52upx;
				height: 52upx;
			}
		}
	}
</style>
